// <copyright file="DirectionalDataFlanks.cs" company="TenneySoftware">
// Copyright (c) 2009 All Right Reserved
// </copyright>
// <author>Robert Tenney</author>
// <email>rob10e@yahoo.com</email>
// <date>April 2009</date>
// <summary>A class to determine data related to the points to the left and right of a certain point based on the direction given.</summary>

// License:

// Product: RPGRoguelikeEngine .Net
// Author: Robert N. Tenney
// Copyright: April 2009

// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation version 2
// of the License.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

// This license covers all source code, binaries, and other materials related to this project
// unless specifically stated otherwise.

using System;
using System.Drawing;

namespace TenneySoftware.Engine {
    /// <summary>
    /// A class to determine data related to the points to the left and right of a certain
    /// point based on the direction given.
    /// </summary>
    public class DirectionalDataFlanks {
        /// <summary>
        /// Point to the left of center.
        /// </summary>
        private Point left;

        /// <summary>
        /// Point to the right of center.
        /// </summary>
        private Point right;

        /// <summary>
        /// Center point.
        /// </summary>
        private Point center;

        /// <summary>
        /// Direction to the left of center.
        /// </summary>
        private Direction leftDirection;

        /// <summary>
        /// Direction to the right of center.
        /// </summary>
        private Direction rightDirection;

        /// <summary>
        /// Gets the point to the left of center.
        /// </summary>
        /// <value>
        /// The point to the left of center.
        /// </value>
        public Point Left {
            get {
                return this.left;
            }
        }

        /// <summary>
        /// Gets the point to the right of center.
        /// </summary>
        /// <value>
        /// The point to the right of center.
        /// </value>
        public Point Right {
            get {
                return this.right;
            }
        }

        /// <summary>
        /// Gets the center point.
        /// </summary>
        /// <value>
        /// The center point.</value>
        public Point Center {
            get {
                return this.center;
            }
        }

        /// <summary>
        /// Gets the direction to the left of center.
        /// </summary>
        /// <value>
        /// The direction to the left of center.
        /// </value>
        public Direction LeftDirection {
            get {
                return this.leftDirection;
            }
        }

        /// <summary>
        /// Gets the direction to the right of center.
        /// </summary>
        /// <value>
        /// The direction to the right of center.
        /// </value>
        public Direction RightDirection {
            get {
                return this.rightDirection;
            }
        }

        /// <summary>
        /// A static method to retrieve the left and right location relative to a given location
        /// and direction.
        /// </summary>
        /// <param name="location">Referance location.</param>
        /// <param name="direction">Direction that the location is facing.</param>
        /// <returns>A DirectionalDataFlanks object that contains only the left and right points
        /// with their directions.</returns>
        public static DirectionalDataFlanks DirectionalRelationFlanksOnly(Point location, Direction direction) {
            DirectionalDataFlanks result = new DirectionalDataFlanks();
            DirectionalDataFlanks offset = new DirectionalDataFlanks();
            Point offsetForward = new Point();
            Point offsetBehind = new Point();
            offsetForward.X = 0;
            offsetForward.Y = -1;
            offsetBehind.X = 0;
            offsetBehind.Y = 1;
            offset.left.X = -1;
            offset.left.Y = 0;
            offset.right.X = 1;
            offset.right.Y = 0;

            switch (direction) {
                case Direction.North:
                    result = offset;
                    result.leftDirection = Direction.West;
                    result.rightDirection = Direction.East;
                    break;
                case Direction.South:
                    result.left = offset.right;
                    result.right = offset.left;
                    result.leftDirection = Direction.East;
                    result.rightDirection = Direction.West;
                    break;
                case Direction.East:
                    result.left = offsetForward;
                    result.right = offsetBehind;
                    result.leftDirection = Direction.North;
                    result.rightDirection = Direction.South;
                    break;
                case Direction.West:
                    result.left = offsetBehind;
                    result.right = offsetForward;
                    result.leftDirection = Direction.South;
                    result.rightDirection = Direction.North;
                    break;
            }
            
            result.left.Offset(location);
            result.right.Offset(location);
            result.center = location;
            return result;
        }

        /// <summary>
        /// Method to convert the points within the structure to an array of Points.
        /// The points are listed from Left to Right.
        /// </summary>
        /// <returns>A Point array of locations.</returns>
        public Point[] ToArray() {
            Point[] temp = new Point[9];
            temp[0] = this.left;
            temp[1] = this.center;
            temp[2] = this.right;
            return temp;
        }
    }
}
